<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        // JS的正则表达式，提供两种定义语法
        // 1. 字面量定义规则
        let regexp1 = /\d/; // 判断字符是否是数值
        console.log(regexp1);
        // 2. 通过构造器定义正则表达式
        let regexp2 = new RegExp("\\d");
        console.log(regexp2);
        

        let telReg = /1\d{10}/;  // 无范围界定正则
        let tel1 = "asdasdasdasdasd";
        let tel2 = "13911111111";
        let tel3 = "aa13911111111bb";

        
        console.log( telReg.test(tel1) );
        console.log( telReg.test(tel2) );
        // 只要字符串中存在符合正则规则的字符子串，均返回true
        console.log( telReg.test(tel3) ); 

        let telReg1 = /^1\d{10}$/;  // 范围界定正则
        console.log( telReg1.test(tel3) ); 


        let str1 = "as2d3a5sa7das4da2sd";
        let arr1 = str1.split(/\d/);
        console.log(arr1);

        let repStr1 = str1.replace(/\d/,"*");
        console.log(repStr1);
        // JS正则表达式存在修饰符关键字 g i 
        //      修饰符关键字被定义在 字面量正则的 末尾
        //      g 表示对整个字符串所有符合正则规则字符进行匹配
        //      i 忽略大小写
        let repStr2 = str1.replaceAll(/\d/g,"*");
        console.log(repStr2);

        let repStr3 = str1.replace(/\d/g,"*");
        console.log(repStr3);
    </script>
</head>
<body>
    
</body>
</html>